CE.record = false

function CE.Record()
	if CE.record then
		CE.record = false
		DEFAULT_CHAT_FRAME:AddMessage("|H|h|cffFF0000"..CE_Locales.func.RecordFalse.."|h")
		Tab4_Button2:SetText("False")
	else
		CE.record = true
		DEFAULT_CHAT_FRAME:AddMessage("|H|h|cff00FF00"..CE_Locales.func.RecordTrue.."|h")
		Tab4_Button2:SetText("True")
	end
end

function CE.Print()
	_mob = UnitName("target")
	if _mob == nil then
		DEFAULT_CHAT_FRAME:AddMessage(TEXT("SC_422203_2"))
	elseif EnemySkills[_mob] == nil then
		DEFAULT_CHAT_FRAME:AddMessage(CE_Locales.func.NoRecord.." (".._mob..")")
	else
		for k,v in pairs(EnemySkills[_mob]) do
			DEFAULT_CHAT_FRAME:AddMessage(_mob.." skill "..k.." = ["..v.."]")
		end
	end
end
	
function CE.BuffCheck(_arg)
	local dropdown = CE_Settings[CE.playerName]["Tab3"]["HpDef"]
	local dropdown1 = CE_Settings[CE.playerName]["Tab3"]["DmgFood"]
	local dropdown2 = CE_Settings[CE.playerName]["Tab3"]["SpeedPot"]
	local dropdown3 = CE_Settings[CE.playerName]["Tab3"]["CritFood"]
	local dropdown4 = CE_Settings[CE.playerName]["Tab3"]["CritPot"]
	local dropdown5 = CE_Settings[CE.playerName]["Tab3"]["Sigil"]
	local dropdown6 = CE_Settings[CE.playerName]["Tab3"]["ItemShop"]
	-- Hp/Defense food
	if _arg == "HpDef" then
		-- Hp Food
		if dropdown == 206874 then return 506271	-- lv 50
		-- Physical Defense Food
		elseif dropdown == 207020 then return 506122	-- lv 50 
		elseif dropdown == 207662 then return 507018	-- lv 60
		elseif dropdown == 207663 then return 507019	-- lv 65
		elseif dropdown == 207664 then return 507020	-- lv 70
		elseif dropdown == 207665 then return 507021	-- lv 75
		elseif dropdown == 207666 then return 507022	-- lv 80
		-- Magical Defense Food
		elseif dropdown == 207021 then return 506123	-- lv 50
		--<Debuging>--
		elseif dropdown == nil then
			--SendSystemMsg("|H|h|cff00FFFF"..CE_Locales.Diyce.HpDef.."|h")
			DEFAULT_CHAT_FRAME:AddMessage("|H|h|cff00FFFF"..CE_Locales.Diyce.HpDef.."|h")
		end
	-- Attack/Damage food
	elseif _arg == "DmgFood" then
		-- Magic damage food
		if dropdown1 == 206878 then return 506120		-- lv 50
		elseif dropdown1 == 207644 then return 507063	-- lv 60
		elseif dropdown1 == 207645 then return 507064	-- lv 65
		elseif dropdown1 == 207646 then return 507065	-- lv 70
		elseif dropdown1 == 207647 then return 507066	-- lv 75
		elseif dropdown1 == 207648 then return 507067	-- lv 80
		elseif dropdown1 == 207649 then return 507068	-- lv 85
		-- Physic damage food
		elseif dropdown1 == 206876 then return 506273	-- lv 50
		elseif dropdown1 == 207653 then return 507045	-- lv 60
		elseif dropdown1 == 207654 then return 507046	-- lv 65
		elseif dropdown1 == 207655 then return 507047	-- lv 70
		elseif dropdown1 == 207656 then return 507048	-- lv 75
		elseif dropdown1 == 207657 then return 507049	-- lv 80
		elseif dropdown1 == 207658 then return 507050	-- lv 85
		-- Magic attack food
		elseif dropdown1 == 206890 then return 506121	-- lv 50
		elseif dropdown1 == 207635 then return 507054	-- lv 60
		elseif dropdown1 == 207636 then return 507055	-- lv 65
		elseif dropdown1 == 207637 then return 507056	-- lv 70
		elseif dropdown1 == 207638 then return 507057	-- lv 75
		elseif dropdown1 == 207639 then return 507058	-- lv 80
		elseif dropdown1 == 207640 then return 507059	-- lv 85
		-- Physic Attack food
		elseif dropdown1 == 200359 then return 501631	-- hot stew
		elseif dropdown1 == 206877 then return 506119	-- lv 50
		elseif dropdown1 == 207604 then return 507036	-- lv 60
		elseif dropdown1 == 207605 then return 507037	-- lv 65
		elseif dropdown1 == 207606 then return 507038	-- lv 70
		elseif dropdown1 == 207607 then return 507039	-- lv 75
		elseif dropdown1 == 207608 then return 507040	-- lv 80
		elseif dropdown1 == 207609 then return 507041	-- lv 85
		--<Debuging>--
		elseif dropdown1 == nil then
			--SendSystemMsg("|H|h|cff00FFFF"..CE_Locales.Diyce.DmgFood.."|h")
			DEFAULT_CHAT_FRAME:AddMessage("|H|h|cff00FFFF"..CE_Locales.Diyce.DmgFood.."|h")
		end	
	-- cast or attack speed pot
	elseif _arg == "SpeedPot" then
		-- casting speed
		if dropdown2 == 200192 then return 500112		-- Ancient Spirit Water
		elseif dropdown2 == 200176 then return 500111	-- Witch Doctor Elixir
		-- attack speed
		elseif dropdown2 == 200173 then return 501321	-- Strong Stimulant
		elseif dropdown2 == 200160 then return 501320	-- Stimulant
		--<Debuging>--
		elseif dropdown2 == nil then
			--SendSystemMsg("|H|h|cff00FFFF"..CE_Locales.Diyce.SpeedPot.."|h")
			DEFAULT_CHAT_FRAME:AddMessage("|H|h|cff00FFFF"..CE_Locales.Diyce.SpeedPot.."|h")
		end
	-- Critical Hit/Damage food
	elseif _arg == "CritFood" then
		-- Magical Critical Food
		if dropdown3 == 200115 then return 501155		-- Moti Blended Sausage
		elseif dropdown3 == 200122 then return 501162	-- Dinner of the Gods
		-- Physical Critical Food
		elseif dropdown3 == 200098 then return 501138	-- Caviar Sandwich
		elseif dropdown3 == 207211 then return 506675	-- Housekeeper Special Caviar Sandwich
		--<Debuging>--
		elseif dropdown3 == nil then
			--SendSystemMsg(""|H|h|cff00FFFF"..CE_Locales.Diyce.CritFood.."|h")
			DEFAULT_CHAT_FRAME:AddMessage("|H|h|cff00FFFF"..CE_Locales.Diyce.CritFood.."|h")
		end
	-- Critical Hit/Damage Pot
	elseif _arg == "CritPot" then
		-- Magical Critical Pot
		if dropdown4 == 206886 then return 506130		-- Demonic Ruin Potion
		elseif dropdown4 == 240535 then return 507126	-- Extinguish Potion
		-- Physical Critical pot
		elseif dropdown4 == 206888 then return 506131	-- Potion of Annihilation
		elseif dropdown4 == 240534 then return 507125	-- Extinction Potion
		--<Debuging>--
		elseif dropdown4 == nil then
			--SendSystemMsg("|H|h|cff00FFFFPlease select Crit Pot|h")
			DEFAULT_CHAT_FRAME:AddMessage(CE_Locales.Diyce.CritPot)
		end
	-- Sigils
	elseif _arg == "Sigil" then
		-- Magical
		if dropdown5 == 200927 then return 501002		-- Magic Attack Sigil
		elseif dropdown5 == 200962 then return 501003	-- Magic Defense Sigil
		-- Physical
		elseif dropdown5 == 200056 then return 500999	-- Attack Sigil
		elseif dropdown5 == 200055 then return 501000	-- Defense Sigil
		--<Debuging>--
		elseif dropdown5 == nil then
			--SendSystemMsg("|H|h|cff00FFFFPlease select Sigil|h")
			DEFAULT_CHAT_FRAME:AddMessage(CE_Locales.Diyce.Sigil)
		end
	-- ItemShop Hp/Defence food
	elseif _arg == "ItemShop" then
		if dropdown6 == 202240 then return 501614		-- Egg Rice Dumplings
		elseif dropdown6 == 203024 then return 502704	-- Flover God Blessing
		--<Debuging>--
		elseif dropdown6 == nil then
			--SendSystemMsg("|H|h|cff00FFFFPlease select Sigil|h")
			DEFAULT_CHAT_FRAME:AddMessage(CE_Locales.Diyce.ItemShop)
		end
	end
end

function CE.HaveItem(_arg)
	if GetBagItemCount(_arg) >= 1 then
		return true
	else
		return false
	end
end
	
function CE.Pot()	
	local phealth = PctH("player")
	local PotA		= 203494
	local WaterA	= 203489
	
	if phealth < 0.20 then
		UseItemByName(TEXT("Sys"..tostring(PotA + 4).."_name"))  
		UseItemByName(TEXT("Sys"..tostring(WaterA + 4).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 3).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 3).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA).."_name"))
	elseif phealth < 0.30 then
		UseItemByName(TEXT("Sys"..tostring(PotA + 3).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 3).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA).."_name"))
	elseif phealth < 0.40 then
		UseItemByName(TEXT("Sys"..tostring(PotA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 2).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA).."_name"))
	elseif phealth < 0.50 then
		UseItemByName(TEXT("Sys"..tostring(PotA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA + 1).."_name"))
		UseItemByName(TEXT("Sys"..tostring(PotA).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA).."_name"))
	elseif phealth < 0.60 then
		UseItemByName(TEXT("Sys"..tostring(PotA).."_name"))
		UseItemByName(TEXT("Sys"..tostring(WaterA).."_name"))
	end
end	

function CE.PotCD()
	local HavePot
	for i = 1, 15 do
		local id = (i - 1) + 203489
		local pot = GetBagItemCount(id)
		local PotName = TEXT("Sys"..id.."_name")
		if pot > 0 then
			HavePot = PotName
			break
		end
	end
	if HavePot ~= nil then
		local occupiedSlots, availableSlots, totalSlots = GetBagCount()
		for slot = 1, totalSlots do
			local inventoryIndex, icon, name, itemCount, locked, quality = GetBagItemInfo (slot)
			local cooldown, remaining = GetBagItemCooldown (inventoryIndex)
			if name == HavePot then
				if (remaining > 1) then
					return false
				else
					return true
				end
			end
		end
	else
		return false
	end
end

function CE.TargetThis(_arg)
	for i=1,10 do
		if UnitName("target") == _arg then
			break
		end
		TargetNearestEnemy()
	end
end

function CE.Item(id)
	TargetUnit("player")
	UseItemByName(TEXT("Sys"..id.."_name")) 
end

function CE.ItemCD(_arg)
	local occupiedSlots, availableSlots, totalSlots = GetBagCount()
	for slot = 1, totalSlots do
		local inventoryIndex, icon, name, itemCount, locked, quality = GetBagItemInfo (slot)
		local cooldown, remaining = GetBagItemCooldown (inventoryIndex)
		if name == _arg then
			if (remaining > 1) then
				return false
			else
				return true
			end
		elseif name == TEXT("Sys".._arg.."_name") then
			if (remaining > 1) then
				return false
			else
				return true
			end
		end
	end
end

function CE.NoCode()
	SendSystemMsg(TEXT("Sys621113_name"))
end

function CE.ISFood()
	local flower = CE_Settings[CE.playerName]["Tab3"]["ItemShop"]
	local pbuffs = BuffList("player")
	if flower == 203024 then
		if pbuffs[501614] then
			SendSystemMsg(TEXT("Sys501614_name").." is stronger buff")
		else
			CE.Item(flower)
		end
	else
		UseItemByName(TEXT("Sys"..flower.."_name"))
	end
end
--[[ 

	/print TEXT("Sys213556_name")



]]